<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseController;
use App\Http\Controllers\Controller;
use App\Http\Requests\MemberRequest;
use App\Models\Admins;
use App\Models\Users;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class MemberController extends BaseController
{


    /**
     * 用户列表
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data=DB::table('users')->paginate(10);
        foreach ($data as &$item){
            $item->created_at=date('Y-m-d H:i',$item->created_at);
            unset($item->password);
        }
     return   $this->success($data);
    }

    /**
     * 添加用戶
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(MemberRequest $request)
    {
        if(Users::create( $request->all()))     return $this->success();
          $this->error('添加失敗');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  @param MemberRequest $request
     * @param $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {


        if(DB::table('users')->where('id',$id)->update($request->all())) return $this->success();
        $this->error('更新失敗');

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {

     if( Users::destroy($id)) return $this->success();
        $this->error('刪除失敗');
    }

    public function updateStatus($id)
    {
        dd($id);
    }
}
